package com.ktjy.controller;
import com.ktjy.entity.Livecommerce;
import com.ktjy.service.LivecommerceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Controller
@RequestMapping("/live")
public class LivecommerceController {
    @Autowired
    private LivecommerceService livecommerceService;
    @GetMapping("/list")
    public String list(Model model) {
        List<Livecommerce> list=livecommerceService.live();
        model.addAttribute("list", list);
        return "list";
    }
    @GetMapping("/list2")
    public String list2(@RequestParam("id") Long id, Model model) {
        Livecommerce livecommerce=livecommerceService.live2(id);
        model.addAttribute("livecommerce", livecommerce);
        return "list2";
    }
    @GetMapping("/Add")
    public String Add() {
        return "Add";
    }
    @PostMapping("/insert")
    public String insert(@ModelAttribute Livecommerce livecommerce) {
        livecommerceService.Add(livecommerce);
        return "redirect:/live/list";

    }
    @GetMapping("/Update")
    public String Update(@RequestParam("id")Long id, Model model) {
        Livecommerce livecommerce=livecommerceService.live2(id);
        model.addAttribute("livecommerce", livecommerce);
        return "Update";
    }
    @PostMapping("/update2")
    public String update2(@ModelAttribute Livecommerce livecommerce) {
        livecommerceService.Update(livecommerce);
        return "redirect:/live/list";
    }
}
